package cn.sirun.com.fca.account.presenter.impl;

import com.tencent.cloud.iov.kernel.model.BaseResponse;
import com.tencent.cloud.iov.util.rx.SimpleObserver;

import cn.sirun.com.fca.account.constant.AccountActionConst;
import cn.sirun.com.fca.account.loader.SettingNewPinLoader;
import cn.sirun.com.fca.account.model.base.CarInfoDetailRequest;
import cn.sirun.com.fca.account.model.base.CarInfoDetailResponse;
import cn.sirun.com.fca.account.model.bind.PinSetFirstRequest;
import cn.sirun.com.fca.account.model.bind.PinSetFirstResponse;
import cn.sirun.com.fca.account.model.bind.PinSetParamResponse;
import cn.sirun.com.fca.account.model.bind.PinSetParamsRequest;
import cn.sirun.com.fca.account.presenter.AccountFlowPresenter;
import cn.sirun.com.fca.account.presenter.ISettingNewPinPresent;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.subjects.BehaviorSubject;

public class SettingNewPinPresenter extends AccountFlowPresenter<SettingNewPinLoader>
        implements ISettingNewPinPresent {

    private BehaviorSubject<BaseResponse> mBehaviorSubject = BehaviorSubject.create();


    @Override
    protected SettingNewPinLoader createLoader() {
        return new SettingNewPinLoader();
    }

    @Override
    public void getPinSetParams(PinSetParamsRequest request) {
        getLoader().getPinSetParams(request)
                .takeUntil(mBehaviorSubject)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SimpleObserver<BaseResponse<PinSetParamResponse>>() {

                    @Override
                    public void onNext(BaseResponse<PinSetParamResponse> submitPhoneResponse) {
                        super.onNext(submitPhoneResponse);
                        SettingNewPinPresenter.this.getActionListener().onAction
                                (AccountActionConst.Normal.ACTION_PIN_SET_PARAMS_RESULT,
                                        submitPhoneResponse);
                    }
                });
    }


    @Override
    public void pinSetFirst(PinSetFirstRequest request) {
        getLoader().pinSetFirst(request)
                .takeUntil(mBehaviorSubject)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SimpleObserver<BaseResponse<PinSetFirstResponse>>() {

                    @Override
                    public void onNext(BaseResponse<PinSetFirstResponse> submitPhoneResponse) {
                        super.onNext(submitPhoneResponse);
                        SettingNewPinPresenter.this.getActionListener().onAction
                                (AccountActionConst.Normal.ACTION_PIN_SET_FIRST_RESULT,
                                        submitPhoneResponse);
                    }
                });
    }

    @Override
    public void pinReset(PinSetFirstRequest request) {
        getLoader().pinReset(request)
                .takeUntil(mBehaviorSubject)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new SimpleObserver<BaseResponse<PinSetFirstResponse>>() {

                    @Override
                    public void onNext(BaseResponse<PinSetFirstResponse> submitPhoneResponse) {
                        super.onNext(submitPhoneResponse);
                        SettingNewPinPresenter.this.getActionListener().onAction
                                (AccountActionConst.Normal.ACTION_PIN_RESET_RESULT,
                                        submitPhoneResponse);
                    }
                });
    }

}
